﻿using System;
using System.Net;

namespace Smile.Network
{
    public class DownloadInfo
    {
        // @Properties
        /// <summary>Gets the size of item to download.</summary>
        ///
        /// <value>The item download size.</value>
        public int Size
        {
            get
            {
                return _size;
            }
        }

        /// <summary>Gets or sets the number of bytes currently downloaded.</summary>
        ///
        /// <value>The number of bytes currently dowloaded.</value>
        public int Downloaded
        {
            get
            {
                return _downloaded;
            }
            internal set
            {
                _downloaded = value;
            }
        }

        /// <summary>Gets or sets the current progress of the download.</summary>
        ///
        /// <value>The current progress of the download (between 0 and 100).</value>
        public int Progress
        {
            get
            {
                return _progress;
            }
            internal set
            {
                if (value <= 100)
                {
                    _progress = value;
                }
                else
                {
                    _progress = 100;
                }
            }
        }


        // @Public
        /// <summary>Default constructor.</summary>
        public DownloadInfo()
        {
        }

        /// <summary>Constructor.</summary>
        ///
        /// <param name="response">The response of a http request.</param>
        public DownloadInfo(HttpWebResponse response)
        {
            _size = Convert.ToInt32(response.ContentLength);
        }


        // @Private
        int _size = 0;
        int _downloaded = 0;
        int _progress = 0;
    }
}
